/*
	YoghurtGum - 2D Game Engine

	Copyright 2009-2011 Quinten Lansu
	
	Licensed under the Apache License, Version 2.0 (the "License"); you may not 
	use this file except in compliance with the License. You may obtain a copy 
	of the License at 
		
		http://www.apache.org/licenses/LICENSE-2.0 
		
	Unless required by applicable law or agreed to in writing, software 
	distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 
	WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 
	License for the specific language governing permissions and limitations 
	under the License. 
*/

#ifndef _YGPLATFORM_H_
#define _YGPLATFORM_H_

/*
	Platforms
*/

#define YG_PLATFORM_TYPE_HPC2000                0
#define YG_PLATFORM_TYPE_HPCPRO	                1
#define YG_PLATFORM_TYPE_POCKETPC2000           2
#define YG_PLATFORM_TYPE_POCKETPC2002           3
#define YG_PLATFORM_TYPE_POCKETPCOTHER          4
#define YG_PLATFORM_TYPE_SMARTPHONE             5

#define YG_PLATFORM_HOST_WINDOWS                0
#define YG_PLATFORM_HOST_LINUX                  1

/*
	Operating Systems
*/

#define YG_OS_TYPE_WINDOWSMOBILE                0
#define YG_OS_TYPE_BADA                         1
#define YG_OS_TYPE_ANDROID                      2
#define YG_OS_TYPE_WINDOWS                      3
#define YG_OS_TYPE_SOMETHINGELSE                1000

#define YG_OS_WINCE201                          0
#define YG_OS_WINCE211                          1
#define YG_OS_WINCE300                          2

/*
	Compilers
*/

#define YG_COMPILER_TYPE_MSVC                   0
#define YG_COMPILER_TYPE_GPP                    1

#define YG_COMPILER_VS6	                        1200
#define YG_COMPILER_VSDOTNET                    1300
#define YG_COMPILER_VS2005                      1400
#define YG_COMPILER_VS2008                      1500
#define YG_COMPILER_GPP                         100

#ifndef YG_OS_TYPE

	/*
		Detect which platform this is being run on.
		Code adapted from: http://www.smartphonedn.com/qa/checkos.html (2010-01-03)
	*/

	#if defined(WIN32_PLATFORM_HPC2000)

		#define YG_PLATFORM_TYPE                YG_PLATFORM_TYPE_HPC2000
		#define YG_TYPE_PLATFORM_NAME           "H/PC 2000"

		#define YG_PLATFORM	                    YG_PLATFORM_HOST_WINDOWS
		#define YG_OS_TYPE                      YG_OS_TYPE_WINDOWSMOBILE

	#elif defined(WIN32_PLATFORM_HPCPRO)

		#define YG_PLATFORM	                    YG_PLATFORM_TYPE_HPCPRO
		#define YG_TYPE_PLATFORM_NAME           "H/PC Pro"

		#define YG_PLATFORM	                    YG_PLATFORM_HOST_WINDOWS
		#define YG_OS_TYPE                      YG_OS_TYPE_WINDOWSMOBILE

	#elif defined(WIN32_PLATFORM_PSPC)

		#if (WIN32_PLATFORM_PSPC == 1)

			#define YG_TYPE_PLATFORM            YG_PLATFORM_TYPE_POCKETPC2000
			#define YG_TYPE_PLATFORM_NAME       "PocketPC 2000"

		#elif (WIN32_PLATFORM_PSPC == 310)

			#define YG_TYPE_PLATFORM            YG_PLATFORM_TYPE_POCKETPC2002
			#define YG_TYPE_PLATFORM_NAME       "PocketPC 2002"

		#else

			#define YG_TYPE_PLATFORM            YG_PLATFORM_TYPE_POCKETPCOTHER
			#define YG_TYPE_PLATFORM_NAME       "PocketPC Other"

		#endif

		#define YG_PLATFORM                     YG_PLATFORM_HOST_WINDOWS
		#define YG_OS_TYPE                      YG_OS_TYPE_WINDOWSMOBILE

	#elif defined(WIN32_PLATFORM_WFSP)

		#define YG_PLATFORM_TYPE                YG_PLATFORM_TYPE_SMARTPHONE
		#define YG_TYPE_PLATFORM_NAME           "Smartphone"

		#define YG_PLATFORM	                    YG_PLATFORM_HOST_WINDOWS
		#define YG_OS_TYPE                      YG_OS_TYPE_WINDOWSMOBILE

	#elif defined(WINCE)

		#define YG_PLATFORM	                    YG_PLATFORM_HOST_WINDOWS
		#define YG_OS_TYPE                      YG_OS_TYPE_WINDOWSMOBILE

	#elif defined(SHP)

		#define YG_PLATFORM	                    YG_PLATFORM_HOST_WINDOWS
		#define YG_OS_TYPE                      YG_OS_TYPE_BADA

	#elif (defined(ANDROID) || defined(OS_ANDROID) || defined(OS_ANDROID))

		#define YG_PLATFORM	                    YG_PLATFORM_HOST_LINUX

	#endif

#endif

/*
	Determine host system
*/

#ifndef YG_PLATFORM

	#if (defined SHP)

		#define YG_PLATFORM	                    YG_PLATFORM_HOST_WINDOWS

	#elif (defined _WINDOWS)

		#define YG_PLATFORM	                    YG_PLATFORM_HOST_WINDOWS

	#elif (defined(ANDROID) || defined(OS_ANDROID) || defined(OS_ANDROID))
		
		#define YG_PLATFORM

	#endif

#endif

/*
	Determine the operating system.
*/

#if (YG_PLATFORM == YG_PLATFORM_HOST_WINDOWS)

	#if (YG_OS_TYPE == YG_OS_TYPE_WINDOWSMOBILE)

		#define YG_OS_TYPE_NAME	                "Windows Mobile"

		#if (_WIN32_WCE == 201)

			#define YG_OS                       YG_OS_WINCE201
			#define YG_OS_NAME                  "Windows CE 2.01"

		#elif (_WIN32_WCE == 211)

			#define YG_OS                       YG_OS_WINCE211
			#define YG_OS_NAME                  "Windows CE 2.11"

		#elif (_WIN32_WCE == 300)

			#define YG_OS                       YG_OS_WINCE300
			#define YG_OS_NAME                  "Windows CE 3.00"

		#endif

	#elif (YG_OS_TYPE == YG_OS_TYPE_BADA)

		#define YG_OS_TYPE_NAME	                "bada"

	#endif

#elif (YG_PLATFORM == YG_PLATFORM_HOST_LINUX)

	#define YG_OS_TYPE                      YG_OS_TYPE_ANDROID
	#define YG_OS_TYPE_NAME                 "Android"

#else

	#define YG_OS_TYPE                      YG_OS_TYPE_SOMETHINGELSE
	#define YG_OS_TYPE_NAME                 "Something Else"

#endif

/*
	Determine which compiler was used to compile this program.
*/

#if (YG_PLATFORM == YG_PLATFORM_HOST_WINDOWS)

	#if (YG_OS_TYPE == YG_OS_TYPE_WINDOWSMOBILE)

		#define YG_COMPILER_TYPE               YG_COMPILER_TYPE_MSVC

	#elif (YG_OS_TYPE == YG_OS_TYPE_BADA)

		#define YG_COMPILER_TYPE               YG_COMPILER_TYPE_GPP

	#endif

#elif (YG_PLATFORM == YG_PLATFORM_HOST_LINUX)

	#define YG_OS_TYPE                     YG_OS_TYPE_ANDROID

	#define YG_COMPILER_TYPE               YG_COMPILER_TYPE_GPP

#endif

/*
	 Compiler-specific defines
*/

#if (YG_COMPILER_TYPE == YG_COMPILER_TYPE_MSVC)

	#define YG_COMPILER_VERSION             _MSC_VER

	#define YG_IMPORT                       __declspec(dllimport)

	#define YG_DLL_IMPORT                   __declspec(dllimport)

	#define YG_ALIGN

	#ifdef YG_DLL

		#define YG_EXPORT                   //__declspec(dllimport)

		#define YG_DLL_EXPORT               __declspec(dllexport)
		#define YG_DLL_EXPORT_LOCAL         __declspec(dllexport)

	#else

		#define YG_EXPORT                   //__declspec(dllexport)

		#define YG_DLL_EXPORT               __declspec(dllimport)
		#define YG_DLL_EXPORT_LOCAL

	#endif

	#if (YG_COMPILER_VERSION >= 1500)

		#define YG_COMPILER                 YG_COMPILER_VS2008
		#define YG_COMPILER_NAME            "Visual Studio 2008"

	#elif (YG_COMPILER_VERSION >= 1400)

		#define YG_COMPILER                 YG_COMPILER_VS2005
		#define YG_COMPILER_NAME            "Visual Studio 2005"

	#elif (YG_COMPILER_VERSION >= 1300)

		#define YG_COMPILER                 YG_COMPILER_VSDOTNET
		#define YG_COMPILER_NAME            "Visual Studio .NET"

	#elif (YG_COMPILER_VERSION >= 1200)

		#define YG_COMPILER                 YG_COMPILER_VS6
		#define YG_COMPILER_NAME            "Visual Studio 6"

	#else
		#error This version of Visual Studio is not supported.
	#endif

#elif (YG_COMPILER_TYPE == YG_COMPILER_TYPE_GPP)

	#define YG_COMPILER_NAME                "G++"

	#define YG_COMPILER_VERSION             (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)

	#define YG_ALIGN                        __attribute__ ((aligned))

	#ifdef YG_DLL

		#define YG_EXPORT                   //__declspec(dllimport)

		#define YG_DLL_EXPORT               __declspec(dllexport)
		#define YG_DLL_EXPORT_LOCAL         __declspec(dllexport)

	#else

		#define YG_EXPORT                   //__declspec(dllexport)

		#define YG_DLL_EXPORT               __declspec(dllimport)
		#define YG_DLL_EXPORT_LOCAL

	#endif

#endif

#if (YG_OS_TYPE == YG_OS_TYPE_WINDOWSMOBILE)

	#define YG_ALLOW_TEMPLATES

	#define YG_MAIN				int WINAPI WinMain(HINSTANCE a_Data, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)

	#define YG_STRING_WIDE_SUPPORT

#elif (YG_OS_TYPE == YG_OS_TYPE_BADA)

	#define YG_MAIN				int WINAPI WinMain(HINSTANCE a_Data, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)

	#define NULL 0

	#define YG_STRING_WIDE_SUPPORT

#elif (YG_OS_TYPE == YG_OS_TYPE_ANDROID)

	// no templates :(

	#define YG_MAIN             int main(char** argc, int argv)

#endif

#endif
